package com.bd.scm.module.utils;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;

/**
 * 日期工具类
 */
public class DateUtil {

    public static List<String> getDayByMonth(int yearParam,int monthParam){
        List<String> list = new ArrayList<>();
        Calendar calendar = Calendar.getInstance(Locale.CHINA);
        calendar.set(yearParam, monthParam-1, 1);
        int year = calendar.get(Calendar.YEAR);//年份
        int month = calendar.get(Calendar.MONTH) + 1;//月份
        int day = calendar.getActualMaximum(Calendar.DATE);
        for (int i = 1; i <= day; i++) {
            String date=null;
            if(month<10 && i<10){
                date = String.valueOf(year)+"-0"+month+"-0"+i;
            }
            if(month<10 && i>=10){
                date = String.valueOf(year)+"-0"+month+"-"+i;
            }
            if(month>=10 && i<10){
                date = String.valueOf(year)+"-"+month+"-0"+i;
            }
            if(month>=10 && i>=10){
                date = String.valueOf(year)+"-"+month+"-"+i;
            }

            list.add(date);
        }
        return list;
    }

    public static void main(String[] args) {
        List<String> dayByMonth = getDayByMonth(2020, 12);
        for (String s : dayByMonth) {
            System.out.println(s);
        }
    }
}
